package com.pro.addresslist.tools;

import java.util.HashMap;
import java.util.Map;


import android.content.Context;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request.Method;
import com.android.volley.toolbox.StringRequest;
import com.pro.addresslist.ui.common.MyApplication;

public class EncryptRequest {
	private static StringRequest stringRequest;
	 
	 public static void RequestJsonPost(Context mContext,String url ,String tag ,final Map<String, String> mMap,EncryptInterface eif){
		 Boolean NetWork= NetUtil.isNetworkAvailable(mContext);
		 if(NetWork){
			 MyApplication.getHttpQueue().cancelAll(tag);
			 stringRequest = new StringRequest(Method.POST,url,eif.jsonObjectListener(),eif.errorListener()){
				 @Override  
				    protected Map<String, String> getParams() throws AuthFailureError {
					 // 参数加密
					 Map<String, String> map=new HashMap<String, String>();
					 for (String key : mMap.keySet()) {
						 String encrypt=BASE64Encrypt.encryptCode(mMap.get(key));
						 map.put(key, encrypt);
						  }  
				        return map;  
				 }
			 };
			// 设置标签
			 stringRequest.setTag(tag);
			// 加入队列
			MyApplication.getHttpQueue().add(stringRequest);
			// 启动
			MyApplication.getHttpQueue().start();
		 }
		 else {
			 Toast.makeText(mContext, "当前网络不可用！", Toast.LENGTH_SHORT).show();
		}
	 }
}
